package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import com.lk.ii.domain.IiAuthor;
import com.lk.ii.service.IIiAuthorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiResearchReport;
import com.lk.ii.service.IIiResearchReportService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 研究报告Controller
 * 
 * @author lk
 * @date 2021-02-22
 */
@Controller
@RequestMapping("/ii/research_report")
public class IiResearchReportController extends BaseController
{
    private String prefix = "ii/research_report";

    @Autowired
    private IIiResearchReportService iiResearchReportService;

    @Autowired
    private IIiAuthorService iiAuthorService;

    @RequiresPermissions("ii:research_report:view")
    @GetMapping()
    public String research_report()
    {
        return prefix + "/research_report";
    }

    /**
     * 查询研究报告列表
     */
    @RequiresPermissions("ii:research_report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiResearchReport iiResearchReport)
    {
        startPage();
        List<IiResearchReport> list = iiResearchReportService.selectIiResearchReportList(iiResearchReport);
        return getDataTable(list);
    }

    /**
     * 导出研究报告列表
     */
    @RequiresPermissions("ii:research_report:export")
    @Log(title = "研究报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiResearchReport iiResearchReport)
    {
        List<IiResearchReport> list = iiResearchReportService.selectIiResearchReportList(iiResearchReport);
        ExcelUtil<IiResearchReport> util = new ExcelUtil<IiResearchReport>(IiResearchReport.class);
        return util.exportExcel(list, "research_report");
    }

    /**
     * 新增研究报告
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        //作者列表
        IiAuthor iiAuthor = new IiAuthor();
        iiAuthor.setStatus(1);
        List<IiAuthor> authors=iiAuthorService.selectIiAuthorList(iiAuthor);
        mmap.put("authors",authors);
        return prefix + "/add";
    }

    /**
     * 新增保存研究报告
     */
    @RequiresPermissions("ii:research_report:add")
    @Log(title = "研究报告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiResearchReport iiResearchReport)
    {
        iiResearchReport.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiResearchReportService.insertIiResearchReport(iiResearchReport));
    }

    /**
     * 修改研究报告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        //作者列表
        IiAuthor iiAuthor = new IiAuthor();
        iiAuthor.setStatus(1);
        List<IiAuthor> authors=iiAuthorService.selectIiAuthorList(iiAuthor);
        mmap.put("authors",authors);
        IiResearchReport iiResearchReport = iiResearchReportService.selectIiResearchReportById(id);
        mmap.put("iiResearchReport", iiResearchReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存研究报告
     */
    @RequiresPermissions("ii:research_report:edit")
    @Log(title = "研究报告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiResearchReport iiResearchReport)
    {
        iiResearchReport.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiResearchReportService.updateIiResearchReport(iiResearchReport));
    }

    /**
     * 删除研究报告
     */
    @RequiresPermissions("ii:research_report:remove")
    @Log(title = "研究报告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiResearchReportService.deleteIiResearchReportByIds(ids));
    }
}
